package service.impl;/*
 *徐韬
 *2021/10/9
 *9:32
 */

import Dao.UserDao;
import Dao.impl.UserDaoimpl;
import Util.DruidUtil;
import entity.User;
import service.UserService;

public class UserServiceImpl implements UserService {
    UserDao userDao = new UserDaoimpl();
    @Override
    public User login(String uAccount, String uPassword) {
        User user = null;
        user = userDao.select(uAccount);
        if(user!=null){
            if(user.getuPassword().equals(uPassword)){
                DruidUtil.close();
                return user;
            }

        }

        return null;
    }

    @Override
    public int update(String newPwd, String uAccount) {
        int result = 0;
        try {
            DruidUtil.begin();
            result = userDao.update(newPwd,uAccount);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;

    }
}
